<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/7/28
 * Time: 下午4:22
 */

namespace app\index\model;


use app\index\service\CategoryService;
use think\Model;

class CompanyCase extends Model
{
    protected $table = "t_companycase";

    public function subcategorys()
    {
        return $this->belongsToMany('SupCategory','t_categorycompanycase',"category_id","companycase_id");
    }
    public static function getCompanyCaseById($id){
        $data = self::where('company_id','=',$id)->select();
        foreach ($data as $item){
            $item['poster'] = config('app.img_prefix').$item['poster'];
            $item['subcategory_id'] = $item['category_id'];
            $item['supcategory_id'] = SubCategory::getSupCateIdById($item['category_id']);

            $item['category_name'] = CategoryService::getCategoryNamesBySubCateId($item['category_id']);

            unset($item['category_id']);

        }
        return $data;
    }
}